/**
 * 
 */
package org.codesmell.util.rendermap;

import java.io.Serializable;
import java.lang.ref.Reference;

public interface TypeConverter extends Serializable
{

    Object convert(Object value);

    public static class TypeConversionException extends RuntimeException
    {
        private static final long serialVersionUID = 1L;

        public TypeConversionException(final String msg)
        {
            super(msg);
        }

        public TypeConversionException(final Throwable e)
        {
            super(e);
        }
    }
    public static class Default implements TypeConverter
    {
        private static final long serialVersionUID = 1L;

        public String convert(final Object value)
        {
            if (value == null)
            {
                return null;
            }
            if (value.getClass().isEnum())
            {
                return ((Enum) value).name();
            }
            if (value instanceof Reference<?>)
            {
                return convert(((Reference<?>) value).get());
            }
            return value.toString();
        }
    }
}